package com.jugheadzhou.mqtt.common;

import java.util.ArrayList;
import java.util.List;

/**
 * mqtt消息发送topic枚举
 * <p color = red>注意：所有在mqttServer上面需要用到的topic都要在这里有值，否则绑定不了topic接收不到消息</p>
 *
 * @author jugheadzhou
 */
public enum TopicEnum {

    /**
     * 基础数据 包含了重传数据
     */
    MDC_MACHINE_STATUS("mdc-machine-status"),
    MACHINE_TEMPERATURE("machine/+/temperature"),
    MACHINE_TEMPERATURE2("machine/#"),
    MACHINE_TEMPERATURE3("test-topic/#"),
    /**
     * 测试分支用
     */
    TEST("test");

    private String topic;

    public String getTopic() {
        return topic;
    }

    TopicEnum(String topic) {
        this.topic = topic;
    }

    public static boolean isExist(String topic) {
        for (TopicEnum topicEnum : TopicEnum.values()) {
            if (topicEnum.getTopic().equalsIgnoreCase(topic)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 获取该枚举类的所有值
     */
    public static String[] getAllValues() {
        List<String> values = new ArrayList<>();
        for (TopicEnum topicEnum : TopicEnum.values()) {
            values.add(topicEnum.getTopic());
        }
        return values.toArray(new String[values.size()]);
    }
}
